package com.xjscrm.common.utils.ww;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.ImmutableMap;
import com.xjscrm.common.enums.RedisCacheKeyEnum;
import com.xjscrm.common.exception.BusinessException;
import com.xjscrm.common.utils.ww.dto.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
 * @author mingyang.chen create in 2024/5/6 18:06
 */
@Slf4j
@Component
public class WwApiUtil implements ApplicationContextAware {

    static RedisTemplate redisTemplate;

    public static final String tokenUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken";
    public static final String bulkSendingAddUrl = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_msg_template?access_token=";
    public static final String bulkSendingStopUrl = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/cancel_groupmsg_send?access_token=";
    public static final String tagMembersUrl = "https://qyapi.weixin.qq.com/cgi-bin/tag/get?access_token=%s&tagid=%s";
    public static final String uploadTempMediaUrl = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s";
    public static final String getTempMediaUrl = "https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s";
    public static final String uploadImageMediaUrl = "https://qyapi.weixin.qq.com/cgi-bin/media/uploadimg?access_token=%s";
    public static final String customerDetailUrl = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get";
    public static final String openIdToUserIdUrl = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_userid?access_token=%s";
    public static final String externalUserIdToUserIdUrl = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/convert_to_openid?access_token=%s";
    public static final String unionidToExternalUserIdUrl = "https://qyapi.weixin.qq.com/cgi-bin/idconvert/unionid_to_external_userid?access_token=%s";
    public static final String getAllTagUrl = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_corp_tag_list?access_token=%s";
    public static final String addTagUrl = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_corp_tag?access_token=%s";
    public static final String editTagUrl = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/edit_corp_tag?access_token=%s";
    public static final String delTagUrl = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_corp_tag?access_token=%s";
    public static final String markTagUrl = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag?access_token=%s";

    public static final String getAppTokenUrl = "https://qyapi.weixin.qq.com/cgi-bin/service/get_suite_token";
    public static final String getAppSecretUrl = "https://qyapi.weixin.qq.com/cgi-bin/service/get_permanent_code?suite_access_token=%s";
    public static final String getAppAccessTokenUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken";
    public static final String getProviderToken = "https://qyapi.weixin.qq.com/cgi-bin/service/get_provider_token";
    public static final String corpidToOpencorpid = "https://qyapi.weixin.qq.com/cgi-bin/service/corpid_to_opencorpid?provider_access_token=%s";
    public static final String useridToOpenuserid = "https://qyapi.weixin.qq.com/cgi-bin/batch/userid_to_openuserid?access_token=%s";

    /**
     * 代开发授权应用access_token的获取
     *
     * @param corpId
     * @param corpSecret
     * @return
     */
    public static String getAppAccessToken(String corpId, String corpSecret) {
        String cacheKey = String.format(RedisCacheKeyEnum.XJ_WW_APP_TOKEN.getKey(), corpId);
        String token = (String) redisTemplate.opsForValue().get(cacheKey);
        if (StringUtils.isNotBlank(token)) {
            return token;
        }
        Map<String, Object> body = ImmutableMap.of("corpid", corpId, "corpsecret", corpSecret);

        String responseJsonStr = HttpUtil.get(getAppAccessTokenUrl, body);
        WwTokenResultDTO wwTokenResultDTO = JSON.parseObject(responseJsonStr, WwTokenResultDTO.class);
        if (Objects.isNull(wwTokenResultDTO) || !wwTokenResultDTO.success()) {
            throw new BusinessException(wwTokenResultDTO.getErrmsg());
        }
        String accessToken = wwTokenResultDTO.getAccess_token();
        redisTemplate.opsForValue().set(cacheKey, accessToken, wwTokenResultDTO.getExpires_in() - 100, TimeUnit.SECONDS);
        return accessToken;
    }

    /**
     *
     * 代开发授权应用secret的获取
     *
     * @param siteToken
     * @param auth_code
     * @return
     */
    public static WwAppSecretResultDTO getAppSecret(String siteToken, String auth_code) {

        Map<String, Object> body = ImmutableMap.of("auth_code", auth_code);

        String responseJsonStr = HttpUtil.post(String.format(getAppSecretUrl, siteToken), JSON.toJSONString(body));
        WwAppSecretResultDTO wwTokenResultDTO = JSON.parseObject(responseJsonStr, WwAppSecretResultDTO.class);
        if (Objects.isNull(wwTokenResultDTO) || !wwTokenResultDTO.success()) {
            throw new BusinessException(wwTokenResultDTO.getErrmsg());
        }
        return wwTokenResultDTO;
    }


    /**
     * 获取代开发应用模板凭证
     *
     * @param suite_id
     * @param suite_secret
     * @param suite_ticket
     * @return access_token
     */
    public static String getSiteToken(String suite_id, String suite_secret, String suite_ticket) {
        log.info("suite_id:{},suite_secret:{},suite_ticket:{}", suite_id, suite_secret, suite_ticket);
        String cacheKey = String.format(RedisCacheKeyEnum.XJ_WW_SITE_TOKEN.getKey(), suite_id);
        String token = (String) redisTemplate.opsForValue().get(cacheKey);
        if (StringUtils.isNotBlank(token)) {
            return token;
        }
        Map<String, Object> body = ImmutableMap.of("suite_id", suite_id, "suite_secret", suite_secret, "suite_ticket", suite_ticket);

        String responseJsonStr = HttpUtil.post(getAppTokenUrl, JSON.toJSONString(body));
        WwTokenResultDTO wwTokenResultDTO = JSON.parseObject(responseJsonStr, WwTokenResultDTO.class);
        log.info("site token: {}", JSON.toJSONString(wwTokenResultDTO));
        if (Objects.isNull(wwTokenResultDTO) || !wwTokenResultDTO.success()) {
            throw new BusinessException(wwTokenResultDTO.getErrmsg());
        }
        String accessToken = wwTokenResultDTO.getSuite_access_token();
        redisTemplate.opsForValue().set(cacheKey, accessToken, wwTokenResultDTO.getExpires_in() - 100, TimeUnit.SECONDS);
        return accessToken;
    }


    public static String getSiteTokenV1() {

        String siteId = (String) redisTemplate.opsForValue().get(RedisCacheKeyEnum.XJ_WW_SITE_ID.getKey());
        String siteSecret = (String) redisTemplate.opsForValue().get(RedisCacheKeyEnum.XJ_WW_SITE_SECRET.getKey());
        String siteTicket = (String) redisTemplate.opsForValue().get(RedisCacheKeyEnum.XJ_WW_SITE_TICKET.getKey());

        return getSiteToken(siteId, siteSecret, siteTicket);
    }

    /**
     * 获取代开发应用模板凭证
     *
     * @param corpId
     * @param provider_secret
     * @return access_token
     */
    public static String getProviderToken(String corpId, String provider_secret) {
        log.info("corpId:{},providerSecret:{}", corpId, provider_secret);
        String cacheKey = String.format(RedisCacheKeyEnum.XJ_WW_PROVIDER_TOKEN.getKey(), corpId);
        String token = (String) redisTemplate.opsForValue().get(cacheKey);
        if (StringUtils.isNotBlank(token)) {
            return token;
        }
        Map<String, Object> body = ImmutableMap.of("corpId", corpId, "provider_secret", provider_secret);

        String responseJsonStr = HttpUtil.post(getProviderToken, JSON.toJSONString(body));
        WwProviderTokenResultDTO wwProviderTokenResultDTO = JSON.parseObject(responseJsonStr, WwProviderTokenResultDTO.class);
        log.info("provider token: {}", JSON.toJSONString(wwProviderTokenResultDTO));
        if (Objects.isNull(wwProviderTokenResultDTO) || !wwProviderTokenResultDTO.success()) {
            throw new BusinessException(wwProviderTokenResultDTO.getErrmsg());
        }
        String accessToken = wwProviderTokenResultDTO.getProvider_access_token();
        redisTemplate.opsForValue().set(cacheKey, accessToken, wwProviderTokenResultDTO.getExpires_in() - 100, TimeUnit.SECONDS);
        return accessToken;
    }

    /**
     * 用于将企业主体的明文corpid转换为服务商主体的密文corpid。
     *
     * @param corpid
     * @param provider_access_token
     * @return
     */
    public static CorpidToOpencorpidResultDTO corpidToOpencorpid(String corpid, String provider_access_token) {

        Map<String, Object> body = ImmutableMap.of("corpid", corpid);

        String responseJsonStr = HttpUtil.post(String.format(corpidToOpencorpid, provider_access_token), JSON.toJSONString(body));
        CorpidToOpencorpidResultDTO corpidToOpencorpidResultDTO = JSON.parseObject(responseJsonStr, CorpidToOpencorpidResultDTO.class);
        if (Objects.isNull(corpidToOpencorpidResultDTO) || !corpidToOpencorpidResultDTO.success()) {
            throw new BusinessException(corpidToOpencorpidResultDTO.getErrmsg());
        }
        return corpidToOpencorpidResultDTO;
    }

    /**
     * 将企业主体下的明文userid转换为服务商主体下的密文userid。
     *
     * @param userid_list
     * @param app_access_token
     * @return
     */
    public static UseridToOpenuseridResultDTO userToOpenuserid(List<String> userid_list, String app_access_token) {

        Map<String, Object> body = ImmutableMap.of("userid_list", userid_list);

        String responseJsonStr = HttpUtil.post(String.format(useridToOpenuserid, app_access_token), JSON.toJSONString(body));
        UseridToOpenuseridResultDTO useridToOpenuseridResultDTO = JSON.parseObject(responseJsonStr, UseridToOpenuseridResultDTO.class);
        if (Objects.isNull(useridToOpenuseridResultDTO) || !useridToOpenuseridResultDTO.success()) {
            throw new BusinessException(useridToOpenuseridResultDTO.getErrmsg());
        }
        return useridToOpenuseridResultDTO;
    }



    // 打标签
    public static Boolean markTag(String accessToken, WwTagMarkDTO tagMark) {

        String markTagJsonStr = HttpUtil.post(String.format(markTagUrl, accessToken), JSON.toJSONString(tagMark));
        WwBaseResultDTO baseResult = JSON.parseObject(markTagJsonStr, WwBaseResultDTO.class);
        if (Objects.isNull(baseResult) || !baseResult.success()) {
            throw new BusinessException(baseResult.getErrmsg());
        }
        return baseResult.success();
    }

    // 删除标签
    // tag_id和group_id不可同时为空。
    // 如果一个标签组下所有的标签均被删除，则标签组会被自动删除。
    public static Boolean delTag(String accessToken, List<String> tagIds, List<String> groupIds) {
        Map<String, Object> params = new HashMap<>();
        if (ObjectUtil.isNotEmpty(tagIds)) {
            params.put("tag_id", tagIds);
        }
        if (ObjectUtil.isNotEmpty(groupIds)) {
            params.put("group_id", groupIds);
        }
        String getTagJsonStr = HttpUtil.post(String.format(delTagUrl, accessToken), JSON.toJSONString(params));
        WwBaseResultDTO baseResult = JSON.parseObject(getTagJsonStr, WwBaseResultDTO.class);
        if (Objects.isNull(baseResult) || !baseResult.success()) {
            throw new BusinessException(baseResult.getErrmsg());
        }
        return baseResult.success();
    }

    // 修改标签
    public static Boolean editTag(String accessToken, WwTagEditDTO tagEdit) {

        String getTagJsonStr = HttpUtil.post(String.format(editTagUrl, accessToken), JSON.toJSONString(tagEdit));
        WwBaseResultDTO baseResult = JSON.parseObject(getTagJsonStr, WwBaseResultDTO.class);
        if (Objects.isNull(baseResult) || !baseResult.success()) {
            throw new BusinessException(baseResult.getErrmsg());
        }
        return baseResult.success();
    }

    // 获取标签
    public static WwTagGetResultDTO listTag(String accessToken, List<String> tagIds, List<String> groupIds) {
        Map<String, Object> params = new HashMap<>();
        if (ObjectUtil.isNotEmpty(tagIds)) {
            params.put("tag_id", tagIds);
        }
        if (ObjectUtil.isNotEmpty(groupIds)) {
            params.put("group_id", groupIds);
        }
        String getTagJsonStr = HttpUtil.post(String.format(getAllTagUrl, accessToken), JSON.toJSONString(params));
        WwTagGetResultDTO getTagResult = JSON.parseObject(getTagJsonStr, WwTagGetResultDTO.class);
        if (Objects.isNull(getTagResult) || !getTagResult.success()) {
            throw new BusinessException(getTagResult.getErrmsg());
        }
        return getTagResult;
    }

    // 创建标签
    public static WwTagAddResultDTO addTag(String accessToken, WwTagAddDTO tagAdd) {

        String addTagJsonStr = HttpUtil.post(String.format(addTagUrl, accessToken), JSON.toJSONString(tagAdd));
        WwTagAddResultDTO addTagResult = JSON.parseObject(addTagJsonStr, WwTagAddResultDTO.class);
        if (Objects.isNull(addTagResult) || !addTagResult.success()) {
            throw new BusinessException(addTagResult.getErrmsg());
        }
        return addTagResult;
    }

    /**
     * 获取令牌
     *
     * @param corpId     企业id
     * @param corpSecret 企业秘钥
     * @return 令牌
     */
    public static String getAccessToken(String corpId, String corpSecret) {
        String cacheKey = String.format(RedisCacheKeyEnum.QYWX_TOKEN.getKey(), corpId);
        String token = (String) redisTemplate.opsForValue().get(cacheKey);
        if (StringUtils.isNotBlank(token)) {
            return token;
        }

        String responseJsonStr = HttpUtil.get(tokenUrl, ImmutableMap.of("corpid", corpId, "corpsecret", corpSecret));

        WwTokenResultDTO wwTokenResultDTO = JSON.parseObject(responseJsonStr, WwTokenResultDTO.class);
        if (Objects.isNull(wwTokenResultDTO) || !wwTokenResultDTO.success()) {
            throw new BusinessException(wwTokenResultDTO.getErrmsg());
        }
        String accessToken = wwTokenResultDTO.getAccess_token();

        redisTemplate.opsForValue().set(cacheKey, accessToken, 7100, TimeUnit.SECONDS);
        return accessToken;
    }

    public static String forceGetAccessToken(String corpId, String corpSecret) {

        String responseJsonStr = HttpUtil.get(tokenUrl, ImmutableMap.of("corpid", corpId, "corpsecret", corpSecret));

        WwTokenResultDTO wwTokenResultDTO = JSON.parseObject(responseJsonStr, WwTokenResultDTO.class);
        if (Objects.isNull(wwTokenResultDTO) || !wwTokenResultDTO.success()) {
            throw new BusinessException(wwTokenResultDTO.getErrmsg());
        }
        String cacheKey = String.format(RedisCacheKeyEnum.QYWX_TOKEN.getKey(), corpId);
        String accessToken = wwTokenResultDTO.getAccess_token();
        redisTemplate.opsForValue().set(cacheKey, accessToken, 7100, TimeUnit.SECONDS);
        return accessToken;
    }

    /**
     * 创建群发
     *
     * @param accessToken 令牌
     * @param bulkSend    群发参数
     * @return 群发消息id, 后续停止会使用到
     */
    public static WwCreateBulkSendResultDTO createBulkSending(String accessToken, WwCreateBulkSendDTO bulkSend) {

        HttpRequest post = HttpUtil.createPost(bulkSendingAddUrl + accessToken);
        post.body(JSON.toJSONString(bulkSend));
        String createResponseJsonStr = post.execute().body();

        WwCreateBulkSendResultDTO createBulkSendResultDTO = JSON.parseObject(createResponseJsonStr, WwCreateBulkSendResultDTO.class);
        if (Objects.isNull(createBulkSendResultDTO) || !createBulkSendResultDTO.success()) {
            throw new BusinessException(createBulkSendResultDTO.getErrmsg());
        }
        return createBulkSendResultDTO;
    }

    /**
     * 停止群发
     *
     * @param accessToken   令牌
     * @param bulkSendMsgId 群发消息id, 创建群发后返回
     * @return 是否成功
     */
    public static boolean stopBulkSending(String accessToken, String bulkSendMsgId) {

        HttpRequest post = HttpUtil.createPost(bulkSendingStopUrl + accessToken);
        post.body(JSON.toJSONString(ImmutableMap.of("msgid", bulkSendMsgId)));
        String createResponseJsonStr = post.execute().body();

        WwBaseResultDTO wwBaseResultDTO = JSON.parseObject(createResponseJsonStr, WwBaseResultDTO.class);
        if (Objects.isNull(wwBaseResultDTO) || !wwBaseResultDTO.success()) {
            throw new BusinessException(wwBaseResultDTO.getErrmsg());
        }
        return wwBaseResultDTO.success();
    }

    /**
     * 获取标签成员
     *
     * @param accessToken 令牌
     * @param tagId       标签id
     * @return 标签成员信息
     */
    public static WwTagMembersResultDTO getTagMembers(String accessToken, String tagId) {
        //
        String createResponseJsonStr = HttpUtil.get(tagMembersUrl, ImmutableMap.of("access_token", accessToken, "tagid", tagId));

        return JSON.parseObject(createResponseJsonStr, WwTagMembersResultDTO.class);
    }

    /**
     * 上传临时素材
     *
     * @param accessToken 令牌
     * @param fileUrl     文件地址
     * @param fileType    文件类型, 媒体文件类型，分别有图片（image）、语音（voice）、视频（video），普通文件(file)
     * @return media_id 企业微信素材库的媒体id
     */
    public static String uploadTempMedia(String accessToken, String fileUrl, String fileType) throws IOException {

        String extName = FileUtil.extName(fileUrl);
        File file = FileUtil.createTempFile("." + extName, true);
        HttpUtil.downloadFile(fileUrl, file);

        HttpRequest post = HttpUtil.createPost(String.format(uploadTempMediaUrl, accessToken, fileType));
        post.form("media", file);
        String createResponseJsonStr = post.execute().body();

        WwTempMediaUploadResultDTO tempMediaUploadResult = JSON.parseObject(createResponseJsonStr, WwTempMediaUploadResultDTO.class);
        if (Objects.isNull(tempMediaUploadResult) || !tempMediaUploadResult.success() || StringUtils.isBlank(tempMediaUploadResult.getMedia_id())) {
            throw new BusinessException(tempMediaUploadResult.getErrmsg());
        }
        if (file.delete()) {
            log.info("文件上传成功, 删除临时创建的文件");
        }
        return tempMediaUploadResult.getMedia_id();
    }

    /**
     * 判断素材id是否存在
     *
     * @param accessToken 令牌
     * @param mediaId     媒体id
     * @return true: 媒体存在, false: 不存在
     */
    public static boolean existsTempMedia(String accessToken, String mediaId) {
        HttpRequest get = HttpUtil.createGet(String.format(getTempMediaUrl, accessToken, mediaId));
        HttpResponse httpResponse = get.execute();
        if (httpResponse.isOk()) {
            return false;
        }
        String body = httpResponse.body();
        return !JSONUtil.isTypeJSON(body);
    }

    /**
     * 上传图片素材
     *
     * @param accessToken 令牌
     * @param fileUrl     图片素材链接
     * @return url
     */
    public static String uploadImageMedia(String accessToken, String fileUrl) {

        String extName = FileUtil.extName(fileUrl);
        File file = FileUtil.createTempFile("." + extName, true);
        HttpUtil.downloadFile(fileUrl, file);

        HttpRequest post = HttpUtil.createPost(String.format(uploadImageMediaUrl, accessToken));
        post.form("media", file);
        String createResponseJsonStr = post.execute().body();

        WwImageMediaUploadResultDTO tempMediaUploadResult = JSON.parseObject(createResponseJsonStr, WwImageMediaUploadResultDTO.class);
        if (Objects.isNull(tempMediaUploadResult) || !tempMediaUploadResult.success() || StringUtils.isBlank(tempMediaUploadResult.getUrl())) {
            throw new BusinessException(tempMediaUploadResult.getErrmsg());
        }
        if (file.delete()) {
            log.info("文件上传成功, 删除临时创建的文件");
        }
        return tempMediaUploadResult.getUrl();
    }


    public static WwCustomerResultDTO getCustomerDetail(String accessToken, String external_userid, String cursor) {

        Map<String, Object> stringStringImmutableMap = ImmutableMap.of("access_token", accessToken, "external_userid", external_userid);
        if (StringUtils.isNotBlank(cursor)) {
            stringStringImmutableMap.put("cursor", cursor);
        }

        String createResponseJsonStr = HttpUtil.get(customerDetailUrl, stringStringImmutableMap);

        WwCustomerResultDTO tempMediaUploadResult = JSON.parseObject(createResponseJsonStr, WwCustomerResultDTO.class);
        if (Objects.isNull(tempMediaUploadResult) || !tempMediaUploadResult.success()) {
            throw new BusinessException(tempMediaUploadResult.getErrmsg());
        }
        return tempMediaUploadResult;
    }

    public static String openIdToUserId(String accessToken, String openId) {

        String createResponseJsonStr = HttpUtil.post(String.format(openIdToUserIdUrl, accessToken), JSON.toJSONString(ImmutableMap.of("openid", openId)));

        WwIdConvertResultDTO tempMediaUploadResult = JSON.parseObject(createResponseJsonStr, WwIdConvertResultDTO.class);
        if (Objects.isNull(tempMediaUploadResult) || !tempMediaUploadResult.success()) {
            throw new BusinessException(tempMediaUploadResult.getErrmsg());
        }
        return tempMediaUploadResult.getUserid();
    }

    public static String unionidToExternalUserId(String accessToken, String openId, String unionId) {

        Map<String, String> body = ImmutableMap.of("openid", openId, "unionid", unionId, "subject_type", "1");
        String createResponseJsonStr = HttpUtil.post(String.format(unionidToExternalUserIdUrl, accessToken), JSON.toJSONString(body));

        WwIdConvertResultDTO tempMediaUploadResult = JSON.parseObject(createResponseJsonStr, WwIdConvertResultDTO.class);
        if (Objects.isNull(tempMediaUploadResult) || !tempMediaUploadResult.success()) {
            throw new BusinessException(tempMediaUploadResult.getErrmsg());
        }
        return tempMediaUploadResult.getExternal_userid();
    }

    public static void main(String[] args) throws Exception {
//        System.out.printf(FileUtil.extName("http://www.baidu.conm/demo1.jpg"));
//        String accessToken = getAccessToken("wwbc208e8a07830e99", "rKwPyTDvyDdKjdrwPR0Fzjim3uQxzpvdibjIQFFGZQs");
//        String image = uploadTempMedia(accessToken, "https://yzimage.52youzai.net/d8f60895a1e740b38fade8b520f65ed4.jpg", "image");
        // 3uV_QH0MxrhDLAWfaYy9-UYL46GAoizOhcTc8EQKo3BBtRbrMNAFZJ9L1q_Vydjr8
        // 3KnvObDo-toQOxVXU22bvyzCgxGN2qdI9a7W2g5VliGqC8oKR-s1oSwFl96jyH57l
//        boolean tempMedia = existsTempMedia(accessToken, "3uV_QH0MxrhDLAWfaYy9-UYL46GAoizOhcTc8EQKo3BBtRbrMNAFZJ9L1q_Vydjr8");
//        System.out.println(image);
//        System.out.println(tempMedia);
//        boolean tempMedia1 = existsTempMedia(accessToken, "3uV_QH0MxrhDLAWfaYy9-111111");
//        System.out.println(image);
//        System.out.println(tempMedia1);
//        WwCustomerResultDTO wmTufyCAAAcz9G3yd0heBrVwnT5lLYa = getCustomerDetail(accessToken, "wmTufyCAAAcz9G3yd0heBrVwnT5lL_YA", null);
//        System.out.println(wmTufyCAAAcz9G3yd0heBrVwnT5lLYa);
//        String s = openIdToUserId(accessToken, "o9cq80y30qaI6nc0xV0ue-8EXTFM");
//        System.out.println(s);

//        String s = unionidToExternalUserId(accessToken, "o9cq800C8CovnCEPia050ezxjOK4", "ozynqsrz1eBiFYpNZ9SXqc6ejEU0");
//        System.out.println(s);
        boolean b = stopBulkSending("9Ahxd8daa5vi_1byUU4WQ9IRmgPhB3whPNyYTxd2bjP3NNA1eim8MDdFNPTiByErSCgi8XZm6Ysniq5NNi3DLuSB1ouFZfc2Pr7nvOomRqTXsqMlTApw6DYq6dIccFDzRTQ6FVO8eqEPcbJ8jhZUq1Sb9Otk3NMX19JV1zp3zm78J_IoxnoFOjNUPVXgx_FexhPNKbzYwJTkSzIfkr7ATA", "msgTufyCAAAjSzFlxCIYdtnd6meVdk-cA");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        redisTemplate = applicationContext.getBean("redisTemplate", RedisTemplate.class);
    }
}
